#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FIFO "/tmp/myfifo"

main(int argc, char **argv)
{
	int fd;
	char w_buf[100];
	int nwrite;
	/*open the FIFO pipe,and set the nonblock flag*/
	//fd = open(FIFO,O_RDWR|O_NONBLOCK,0);
	fd = open(FIFO,O_RDWR,0);
	if (fd == -1)
	{
		if(errno == ENXIO)	
			printf("open error;no reading process\n");
	}

	if(argc == 1)
	{
		printf("please send something\n");	
	}
	strcpy(w_buf, argv[1]);
	/*write string to the pipe*/
	if((nwrite = write(fd, w_buf,100)) == -1)
	{
		if(errno == EAGAIN)	
			printf("The FIFO has not been read yet.Please try later\n");
	}
	else
		printf("write %s to the FIFO\n", w_buf);
	
}
